package com.xmxsuperstar.app.ttac.handlers;

import java.util.Map;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ListView;

import com.xmxsuperstar.app.ttac.StatusListAdapter;
import com.xmxsuperstar.app.ttc.client.ClientConstants;

public class TimeLineHandler extends Handler {
	private ProgressDialog progressDialog = null;

	@Override
	public void handleMessage(Message msg) {
		if (msg.what == 0) {
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) msg.obj;

			Context context = (Context) map.get("context");

			progressDialog = new ProgressDialog(context);
			progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			progressDialog.setCancelable(false);
			progressDialog.setMessage("Loading...");
			progressDialog.show();

		} else if (msg.what == 1) {
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) msg.obj;

			ListView lv = (ListView) map.get("listView");

			StatusListAdapter adapter = (StatusListAdapter) lv.getAdapter();

			adapter.notifyDataSetChanged();

			if (progressDialog != null) {
				progressDialog.dismiss();
				progressDialog = null;
			}

			Log.i(ClientConstants.LogTag,
					"Count in adapter: " + Integer.toString(adapter.getCount()));

		} else {
			super.handleMessage(msg);
		}
	}
}
